def nachalo(n):
    if n <= 1:
        return False
    if n <= 3:
        return True
    if n % 2 == 0 or n % 3 == 0:
        return False
    i = 5
    while i * i <= n:
        if n % i == 0 or n % (i + 2) == 0:
            return False
        i += 6
    return True

def nachalo_proverka(n):
    p = n
    while True:
        p += 1
        if nachalo(p):
            return p

def nachalo_proverka_p(n):
    p = n
    while p > 2:
        p -= 1
        if nachalo(p):
            return p

def konec(n):
    if not n.isdigit() or len(n) != 3:
        return "Wrong input"
    num = int(n)
    if nachalo(num):
        return num
    next_p = nachalo_proverka_p(num)
    prev_p = nachalo_proverka_p(num)
    if next_p - num < num - prev_p:
        return next_p
    else:
        return prev_p
slovar = {
    'zero': '0', 'one': '1', 'two': '2', 'three': '3', 'four': '4',
    'five': '5', 'six': '6', 'seven': '7', 'eight': '8', 'nine': '9'
}




slova = input().split()
if len(slova) != 3:
    print("Wrong input")
else:
    num_str = ''
    try:
        for word in slova:
            num_str += slovar[word.lower()]
        print(konec(num_str))
    except KeyError:
        print("Wrong input")